<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    let  a=[1,2,3,4,5,6,7,8,9];
    let b;
    let max=a.length-1;
    

    b=prompt('请输入你要查找的数');

    let min=0;
   
    while(max>=min)
    {
     let mid =parseInt((min+max)/2);
    if(a[mid]>b){
        max=mid-1; 
    }
    else if(a[mid]<b){
        min=mid+1;
    }
    else {
        console.log("你找的是第"+(mid+1)+"位数")
    }
    
    }


</script>
</html>